package com.oa.modules.approvalsec1.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.oa.modules.approvalsec1.entity.ExplorationCloudEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 云探勘表
 *
 * @author jiangwei
 * @email 785297226@qq.com
 * @date 2021-04-06 14:12:59
 */
@Mapper
public interface ExplorationCloudDao extends BaseMapper<ExplorationCloudEntity> {


    /**
     * 查询总条数
     *
     * @author jiangwei
     * @email 785297226@qq.com
     * @date 2021-04-06 14:12:59
     * @Description 查询分页数据
     */
//    @Select("<script>SELECT COUNT( 1 ) FROM (" +
//            "select t1.* from exploration_cloud t1  " +
//            "where 1=1 " +
//            "<if test = 'params != null '> "+
//            "and t1.`STATUS` = #{params.status} " +
//            "<if test = 'params.userName'> and t1.USER_NAME LIKE '%${params.userName}%' </if>" +
//            "<if test = 'params.userId'> and t1.CREATE_OPER = #{params.userId} </if>" +
//            "<if test = 'params.isHandler'> and  t1.IS_HANDLER = #{params.isHandler} </if>" +
//            "<if test = 'params.isHandler2'> and  t1.IS_HANDLER in (${params.isHandler2}) </if>" +
//            "<if test = 'params.type!=null and params.type==1'> and  t1.TYPE = '工程建设项目' </if>" +
//            "<if test = 'params.type!=null and params.type==3'> and  t1.TYPE in ('食品','卫生','药品','交通') </if>" +
//            ") </if> TOTAL</script>")
    long findPage(@Param("params") Map<String, Object> params);

    /**
     * 查询分页数据
     *
     * @author jiangwei
     * @email 785297226@qq.com
     * @date 2021-04-06 14:12:59
     * @Description 查询分页数据
     */
//    @Select("<script>select t1.* from exploration_cloud t1 " +
//            "where 1=1 " +
//            "and t1.`STATUS` = #{params.status} " +
//            "<if test = 'params.userName'> and t1.USER_NAME LIKE '%${params.userName}%' </if>" +
//            "<if test = 'params.userId'> and t1.CREATE_OPER = #{params.userId} </if>" +
//            "<if test = 'params.isHandler'> and t1.IS_HANDLER = #{params.isHandler} </if>" +
//            "<if test = 'params.isHandler2'> and  t1.IS_HANDLER in (${params.isHandler2}) </if>" +
//            "<if test = 'params.type!=null and params.type==1'> and  t1.TYPE = '工程建设项目' </if>" +
//            "<if test = 'params.type!=null and params.type==3'> and  t1.TYPE in ('食品','卫生','药品','交通') </if>"+
//            "ORDER BY t1.CREATE_DATE desc</script>")
    List<ExplorationCloudEntity> findRecords(IPage<ExplorationCloudEntity> page, @Param("params") Map<String, Object> params);

    /**
     * 查询分页数据
     *
     * @author jiangwei
     * @email 785297226@qq.com
     * @date 2021-04-06 14:12:59
     * @Description 查询分页数据
     */
    @Select("<script>select t1.* from exploration_cloud t1 " +
            "where 1=1 " +
            "<if test = 'roomNum'> and t1.ROOM_NUM = #{roomNum} </if>" +
            "</script>")
    ExplorationCloudEntity queryForRoomNum(@Param("roomNum") String roomNum);

    /**
     * 根据userId查询历史记录总条数
     *
     * @param params
     * @return
     */
    @Select("<script>SELECT COUNT(1) FROM (" +
            "select t1.* from exploration_cloud t1 " +
            "where 1=1 " +
            "<if test='params != null'> " +
            "and t1.`CREATE_OPER` = #{params.userId} " +
            ") </if> TOTAL</script>"
    )
    long findHistoryCount(@Param("params") Map<String, Object> params);

    /**
     * 根据UserId查询历史记录
     */
    @Select("<script>select t1.* from exploration_cloud t1 " +
            "where 1 = 1 " +
            "<if test = 'params != null'>" +
            "and t1.`CREATE_OPER` = #{params.userId}" +
            "</if> order by CREATE_DATE desc </script>")
    List<ExplorationCloudEntity> findHistory(IPage<ExplorationCloudEntity> page, @Param("params") Map<String, Object> params);


}
